﻿<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
    <link href="../lib/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
<script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>入库明细表</title>
</head>
<body>
    <div class="pd-5">
        <div class="row cl" id="findfdiv">
          
            <div class="formControls col-2">
                <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="入库时间" id="findinfodt1_times" name="findinfodt1_times" class="input-text Wdate">
            </div>
            <div class="formControls col-2">
                <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="入库时间" id="findinfodt1_timee" name="findinfodt1_times" class="input-text Wdate">
            </div>
            <div class="formControls col-2">
                <span class="select-box">
                    <select class="select" size="1" name="findtaskfromorgid" id="findtaskfromorgid">
                    </select></span>
            </div>
            <div class="formControls col-2">
                <input type="text" class="input-text" placeholder="输入农作物名称" id="findfv1" name="findfv1">
            </div>
           <div class="formControls col-2">
                        <span class="select-box">
                            <select class="select" size="1" name="findinouttype" id="findinouttype">
                                <option value="">所有</option>
                                <option value="运输入库">运输入库</option>
                                <option value="退货处理">退货处理</option>
                            </select>
                        </span>
                    </div>
            <div class="formControls col-2">
                <button onclick="hcrainpage()" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 查询</button>
            </div>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-5 ">
            <button onclick="method5('hcvueapp')" class="btn btn-secondary  round" id="Button1" name=""><i class="Hui-iconfont">&#xe644;</i>导出</button>
        </div>
        <div id="hcvueapp" class="mt-5 ml-20">
            <div class="panel panel-default" v-for="site in listinfo">
                <div class="panel-header" style="margin: 0px; padding: 0px;">{{ site.fv1 }}--总量：{{ site.storeall }}- 有效量：{{ site.storeokall }}-合计：{{ site.countall}} </div>
                <div class="panel-body" style="margin: 0px; padding: 0px;">
                    <table class="table table-border table-bordered table-hover" style="margin: 0px; padding: 0px;">
                        <thead>
                            <tr>
                                <th>任务信息</th> <th>动作</th><th>人员</th><th>说明</th>
                                <th>状态</th>
                                <th>入库量kg 
                                     <lable v-if="site.subinfo2.length >0">{{site.subinfo2[0].fv3}}包/</lable>
                                    <lable v-if="site.subinfo2.length >1">{{site.subinfo2[1].fv3}}包/</lable>
                                    <lable v-if="site.subinfo2.length >2">{{site.subinfo2[2].fv3}}包</lable>
                                </th>
                                <th>扣率</th>
                                <th>有效量</th>   <th>预计可出成包<lable v-if="site.subinfo2.length >0">规格：{{site.subinfo2[0].fv3}}</lable></th>
                                <th>单价</th>
                                <th>小计</th>
                                <th>已出库kg/包/包/包</th>
                                <th>处理时间</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for="worklist in site.subinfo" v-bind:class="{ success: (worklist.hasoutall<=worklist.storeall), 'warning':worklist.hasoutall>=worklist.storeall }">
                                <td>{{ worklist.taskfromorgname}}-地块：{{ worklist.dkname}}
                               
                                    <br />
                                    采摘：{{ worklist.taskworktime.Value}}</td>
                                <td>{{ worklist.inouttype }}</td>  <td>{{ worklist.jjusername }}</td>  <td>{{ worklist.outdesc }}</td>
                                <td>{{ worklist.productstate }}</td>
                                <td>{{ worklist.storeall }}/{{ worklist.storefortype1 }}/{{ worklist.storefortype2 }}/{{ worklist.storefortype3 }}</td>
                                <td>{{ worklist.kl }}</td>
                                <td>{{ worklist.storeallok }}</td><td>{{ worklist.ggcount1 }}</td>
                                <td>{{ worklist.price }}</td>
                                <td>{{ worklist.moneycount }}</td>
                                <td>{{ worklist.hasoutall }}/{{ worklist.storefortype1out }}/{{ worklist.storefortype2out }}/{{ worklist.storefortype3out }}</td>
                                <td>{{ worklist.dataaddtime.Value }}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="mt-5 row">
                <div id="page1"></div>
            </div>

        </div>
    </div>

    <script type="text/javascript" src="../lib/layui/layui2.js"></script>
    <script type="text/javascript" src="../js/vue.min.js"></script>
    <script>
        var hcvueapp = new Vue({
            el: '#hcvueapp',
            data: {
                listinfo: []
            },
            methods: {

            }
        })
    </script>
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/layer/1.9.3/layer.js"></script>
    <script type="text/javascript" src="../lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript" src="../lib/My97DatePicker/WdatePicker.js"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hcui.js"></script>
    <script type="text/javascript" src="../js/hcui_list.js"></script>

    <script type="text/javascript">
        //基地
        hcdoselbyPost("BranchID as id,BranchName as name", "mrbranch", "type='本部'", "", "", "id", function (data) { SetSelectWithArrayIdName("#findtaskfromorgid", data); });
        var uiform = null;
        var whereaddinfo = "";
        $(function () {
            $("#findinfodt1_times").val((new Date()).Format("yyyy-MM-dd"));//开始时间
            spsetBaseNoBt("yw_baseinfo", "id", "yw_baseinfo as T", "*", "#tablelist", "sctaskoutstore", "生产任务管理", "sctaskoutstore");
            layui.use(['form'], function () {
                uiform = layui.form();
                //人员下拉加载 
                //hcdoselbyPost("empid  as id,concat(depname,'-',empname) as name,empname as username,mobile as  tel,depname as address", "view_user", "branchid='" + HCUser.HCUorg + "'", "", "", "id",
                //    function (data) {
                //        SetSelectWithArrayIdName("#inoutusernamesel", data);
                //        uiform.render();
                //    });
            });

            hcrainpage(1);
        });
        function onchangeneedtodoid() {
            hcvueapp.listinfo.forEach(function (e) {
                e.subinfo.forEach(function (list) {

                    var gg1 = 0;
                    var gg2 = 0;
                    var gg3 = 0;
                    if (e.subinfo2.length > 0) {
                        gg1 = e.subinfo2[0].nv1;
                    }
                    if (e.subinfo2.length > 1) {
                        gg2 = e.subinfo2[1].nv1;
                    }
                    if (e.subinfo2.length > 2) {
                        gg3 = e.subinfo2[2].nv1;
                    }
                    //处理量
                    if (e.subinfo2.length > 0) {
                        list.ggcount1 = (list.storeallok * 1 * e.subinfo2[0].nv3).toFixed(0);
                    }

                    // list.needtoout = (gg1 * 1 * list.storefortype1needout + gg2 * 1 * list.storefortype2needout + gg3 * 1 * list.storefortype3needout).toFixed(2);


                });
            });
        }
        //出库处理
        function savetotaskstre() {
            var needupdate = 0;
            var message = "";//"<input id='ssssssssss'></input>";
            //$("#finouttype").val() == "出库贴码"
            var needtocode = false;
            for (var sp in hcvueapp.listinfo) {
                var subinfo = hcvueapp.listinfo[sp].subinfo;
                message += "<br/> " + hcvueapp.listinfo[sp].fv1 + "[";
                for (var lindex in subinfo) {
                    if (subinfo[lindex].needtoout == null || subinfo[lindex].needtoout == ""
                        || subinfo[lindex].needtoout == " " || subinfo[lindex].needtoout <= 0
                        || isNaN(subinfo[lindex].needtoout)) {
                        continue;
                    }
                    //要是数值
                    if (!hcisnum(subinfo[lindex].storefortype1needout)) {
                        continue;
                    }
                    if (!hcisnum(subinfo[lindex].storefortype2needout)) {
                        continue;
                    }
                    if (!hcisnum(subinfo[lindex].storefortype3needout)) {
                        continue;
                    }
                    if (subinfo[lindex].productstate == "包装品") {
                        needtocode = true;
                    }
                    needupdate++;
                    message += "(" + subinfo[lindex].needtoout + ")";
                }
                message += "]";
            }
            if (needtocode) {
                if ($("#finouttype").val() == "出库加工") {
                    layer.msg('当前处理的物品状态,不能是出库加工', { icon: 2 });
                    return;
                }
            }
            else {
                if ($("#finouttype").val() == "出库贴码") {
                    layer.msg('当前处理的物品状态,不能是出库贴码', { icon: 2 });
                    return;
                }
            }
            layer.confirm('确认信息：记录数：' + needupdate + message, {
                btn: [$("#finouttype").val(), '取消'] //按钮
            }, function () {
                // alert($("#ssssssssss").val());
                savetotaskstreDo();
                // layer.msg('的确很重要', { icon: 1 });
            }, function () {
                //layer.msg('也可以这样', {
                //    time: 20000, //20s后自动关闭
                //    btn: ['明白了', '知道了']
                //});
            });
        }

        function hcrainpage(curr) {
            var finddcno = $("#findfv1").val();
            if (finddcno) {
                whereaddinfo = " and fv1 like '%" + finddcno + "%'";
            }
            else { whereaddinfo = ""; }
            var sunwhereadd2 = "";
            var sunwhereadd1 = "";
            var findtaskfromorgid = $("#findtaskfromorgid").val();
            if (findtaskfromorgid) {
                sunwhereadd1 = " and taskfromorgid=" + findtaskfromorgid;
                sunwhereadd2 = ",taskfromorgid-" + findtaskfromorgid;

            }
            if ($("#findinfodt1_times").val()) {
                sunwhereadd2 += ",dataaddtime-||>=||" + $("#findinfodt1_times").val() + " 00:00:00";
                sunwhereadd1 += " and dataaddtime >= '" + $("#findinfodt1_times").val() + " 00:00:00" + "'";
            }
            if ($("#findinfodt1_timee").val()) {
                sunwhereadd2 += ",dataaddtime-||<=||" + $("#findinfodt1_timee").val() + " 23:59:59";
                sunwhereadd1 += " and dataaddtime <= '" + $("#findinfodt1_timee").val() + " 23:59:59" + "'";
            }
            if ($("#findinouttype").val()) {
                sunwhereadd2 += ",inouttype-" + $("#findinouttype").val();
                sunwhereadd1 += " and inouttype = '" + $("#findinouttype").val() + "'";
            }
            
            $.ajax({
                type: "post",
                url: "../ashx/spui.ashx",
                data: {
                    "action": "getpageinfo",
                    "pagenow": curr || 1,
                    "pagesize": 50,
                    "select": "t.id,t.fv1,t.fv2,0 as storeall,0 countall,0 as storeokall",
                    "table": "yw_baseinfo as t",
                    "group": "",
                    "having": "",
                    "where": " type=1 and maintype=1 " + whereaddinfo + " and id in(select productid from hsc_task_store_process where   databranchid=" + HCUser.HCUorg + " and storehouseid=0 " + sunwhereadd1 + "  )",
                    "order": "",
                    "subinfo":
                        "jjusername,outdesc,inouttype,0 ggcount1,price,kl,storeallok,moneycount,storefortype1,storefortype2,storefortype3,storefortype1out,storefortype2out,storefortype3out,storefortype1-storefortype1out as storefortype1needout ,storefortype2-storefortype2out as storefortype2needout,storefortype3-storefortype3out as storefortype3needout," +
                        "id,taskfromorgid,taskfromorgname,taskid,taskno,tasklistid,productname,dkid,dkname,dataaddtime,storeall,storeall-hasoutall as needtoout,lockcout,hasoutall,outstate,taskworktime,productstate#hsc_task_store_process#productid-@id,databranchid-" + HCUser.HCUorg + ",storehouseid-0" + sunwhereadd2 + "#id#",//子查询   当前物品+当前机构+库存大于0
                    "subinfo2": "id,fv1,fv2,fv3,nv1,nv2,nv3#yw_baseinfo#type-7,fv1-@id#nv2#"//7+当前品种规格
                },
                async: true,
                cache: false,
                error: function (error) {

                },
                success: function (data) {
                    var result = JSON.parse(data);
                    hcvueapp.listinfo = result.data;
                    //if (hcvueapp.listinfo == null || hcvueapp.listinfo.length == 0) {
                    //    result.message = "没有数据"; /// / / layer.msg('没有相关数据噢', { icon: 5 });
                    //}
                    //计算总量
                    hcvueapp.listinfo.forEach(function (e) {
                        e.subinfo.forEach(function (list) {
                            e.storeall = (e.storeall * 1 + (list.storeall * 1)).toFixed(2);
                            e.countall = (e.countall * 1 + (list.moneycount * 1)).toFixed(2);
                            e.storeokall = (e.storeokall * 1 + (list.storeallok * 1)).toFixed(2);
                        });
                    });
                    onchangeneedtodoid();
                    //显示分页
                    laypage({
                        cont: 'page1', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                        pages: result.message || 0, //通过后台拿到的总页数
                        curr: curr || 1, //当前页
                        jump: function (obj, first) { //触发分页后的回调
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                hcrainpage(obj.curr);
                            }
                        }
                    });

                }
            });
        };

        //重新加载-重载
        function findreolad(isback) {
            hcrainpage(1);
        }



    </script>
</body>
</html>
